/**************************************************************************
*   Copyright (C) 2009 Chernov Dmitry                                     *
*   diman4ik.chernov@gmail.com                                            *
*                                                                         *
*   This program is free software; you can redistribute it and/or modify  *
*   it under the terms of the GNU General Public License as published by  *
*   the Free Software Foundation; either version 2 of the License, or     *
*   (at your option) any later version.                                   *
*                                                                         *
*   This program is distributed in the hope that it will be useful,       *
*   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
*   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *
*   GNU General Public License for more details.                          *
*                                                                         *
*   You should have received a copy of the GNU General Public License     *
*   along with this program; if not, write to the                         *
*   Free Software Foundation, Inc.,                                       *
*   59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.             *
***************************************************************************/

#ifndef KORNERS_ENGINE_THREAD
#define KORNERS_ENGINE_THREAD

#include <QThread>
#include <QVector>

#include "korners_game_engine.h"

class KornersScene;


class KornersEngineThread : public QThread
{
    Q_OBJECT
public:

    explicit KornersEngineThread( KornersScene* sc = 0 );
    ~KornersEngineThread();

    void run();
  
    enum StartType
    {
        none = 0,
        ai = 1,
        network_clnt = 2,
        network_serv = 3,
	dual = 4,
        timer = 5,
    };
    
public slots:
    void startGameEngineAI();
    void startGameEngineTimer();
    void startGameEngineDual();
    void startGameEngineNetwork( const QString& net_name, int port, bool server = false,
                                 const QString& ip_adress = "localhost" );

private:

    StartType sType;  
    QVector<QVariant> startParams;
    KornersEngine* curGameEngine;
    KornersScene* m_scene;
    
    inline void restart()
    {
        if( isRunning() )
        {
            quit();
            wait();
            start();
        }
        else
            start();
    }
};

#endif
